package cn.chen.gc;

public class CanReliveObj {

    public static CanReliveObj obj;

    @Override
    protected void finalize() throws Throwable {
        super.finalize();
        System.out.println("CanReliveObj finalize called");
        obj = this;
    }

    @Override
    public String toString() {
        return super.toString();
    }
}

class Main{
    public static void main(String[] args) throws InterruptedException {
        CanReliveObj.obj = new CanReliveObj();
        CanReliveObj.obj = null;
        System.gc();
        Thread.sleep(1000);
        if(CanReliveObj.obj == null)
            System.out.println("obj是null");
        else
            System.out.println("obj可用");
        System.out.println("第二次gc");
        CanReliveObj.obj = null;
        System.gc();
        Thread.sleep(1000);
        if(CanReliveObj.obj == null)
            System.out.println("obj是null");
        else
            System.out.println("obj可用");
    }
}
